package com.smarth.zhizulian.popupwindow;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.smarth.zhizulian.R;
import com.smarth.zhizulian.utils.ShareUtils;

import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * Created by 18865 on 2018/3/5.
 */

public class FriendHongBaoDialog extends Dialog {
    private Activity mActivity;
    private long mCoin;
    private long mId;

    public FriendHongBaoDialog(@NonNull Activity context, long coin, final long id) {
        super(context, R.style.MyDialog);
        this.mActivity = context;
        mCoin = coin;
        mId = id;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_friendshongbao);
        TextView tv_coin = findViewById(R.id.tv_coin);
        tv_coin.setText("+" + mCoin + "金币");
        ImageView iv_yes = findViewById(R.id.iv_yes);
        ImageView iv_no = findViewById(R.id.iv_no);
        ImageView iv_bg = findViewById(R.id.iv_bg);

        if (mCoin >= 30) {
            iv_yes.setVisibility(View.VISIBLE);
            iv_bg.setSelected(true);
        } else {
            iv_no.setVisibility(View.VISIBLE);
            iv_bg.setSelected(false);
        }

        findViewById(R.id.iv_yes).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareUtils.shareHongBaoFriend(mActivity, mId, WechatMoments.NAME, !(mCoin < 30));
                dismiss();
            }
        });

        findViewById(R.id.iv_no).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareUtils.shareHongBaoFriend(mActivity, mId, WechatMoments.NAME, !(mCoin < 30));
                dismiss();
            }
        });

        findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        // 动态设置自定义Dialog的显示内容的宽和高
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
        android.view.WindowManager.LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值
        p.height = d.getHeight();   //高度设置为屏幕的0.3
        p.width = d.getWidth();    //宽度设置为全屏
        getWindow().setAttributes(p);     //设置生效
    }

}
